package top.hcode.hoj.controller.signup;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.common.exception.StatusFailException;
import top.hcode.hoj.common.exception.StatusForbiddenException;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.dto.TeamInfoDTO;
import top.hcode.hoj.service.signup.SignUpService;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * @author 76004
 * @apiNote
 * @date 2023/4/11 14:40
 */
@RestController
@RequestMapping("/api/team")
public class SignUpController {
    @Autowired
    private SignUpService signUpService;

    @PostMapping("/sign-up")
    public CommonResult<Void> signUp(@Valid @RequestBody TeamInfoDTO teamInfoDTO) throws StatusFailException, StatusForbiddenException{
        return signUpService.signUp(teamInfoDTO);
    }

    @PostMapping("/apply-for-update-team-info")
    public CommonResult<Void> applyForUpdateTeamInfo(@Valid @RequestBody TeamInfoDTO teamInfoDTO) throws StatusFailException, StatusForbiddenException{
        return signUpService.applyForUpdateTeamInfo(teamInfoDTO);
    }

    @PutMapping("/check-apply")
    public CommonResult<Void> checkApply(Long tid, Boolean isOk, Long cid) throws StatusFailException, StatusForbiddenException {
        return signUpService.checkApply(tid,isOk,cid);
    }

    @PutMapping("/withdraw-apply")
    public CommonResult<Void>withdrawApply(Long tid) throws StatusForbiddenException, StatusFailException {
        return signUpService.withdrawApply(tid);
    }

    /***
     * 生成报名信息csv
     * @param cid 比赛id
     * @param choose 选择要生成的个人信息，按位与生成从低位到高位以此对应（
     *               1.队员姓名
     *               2.队员学号
     *               3.队员班级
     *               4.队员衣服尺码
     *               5.队员电话号码
     *               6.队员scpc用户名
     *               ）
     * @param response
     * @return
     * @throws IOException
     * @throws StatusFailException
     * @throws StatusForbiddenException
     */
    @GetMapping("/getSignUpCsv")
    public void generateCsvByContestId(Long cid,Long choose, HttpServletResponse response) throws IOException, StatusFailException, StatusForbiddenException{
        signUpService.generateCsvByContestId(cid,choose,response);
    }

    @GetMapping("/test")
    public String test(){
        return "test success";
    }

}
